package fn;

public class Constant extends Function {

	private static final long serialVersionUID = -1123868363594389515L;

	public static final Function E = create(Math.E, "e");
	public static final Function PI = create(Math.PI, "\\pi");
	public static final Function ZERO = create(0);
	public static final Function ONE = create(1);

	private double value;

	private Constant(double val) {
		value = val;
	}

	public static Function create(double val) {
		return create(val, null);
	}

	public static Function create(double val, final String symbol) {
		if (symbol != null)
			return new Constant(val) {
				/**
				 * 
				 */
				private static final long serialVersionUID = -6768965770183961658L;

				public String prefix() {
					return symbol;
				}
			};
		else
			return new Constant(val);
	}

	@Override
	protected Function[] child() {
		return null;
	}

	@Override
	public double evaluate(double sub) {
		return value;
	}

	@Override
	public String prefix() {
		return Global.str(value);
	}

	@Override
	public String infix() {
		return "";
	}

	@Override
	public String postfix() {
		return "";
	}

	@Override
	protected int precedence() {
		return Integer.MAX_VALUE;
	}

	@Override
	protected boolean withPar() {
		return false;
	}

	@Override
	public Function derivative() {
		return ZERO;
	}

	public double value() {
		return value;
	}
}
